<template>
	<view class="goods">
		<goods-list :goods="goods"></goods-list>
		<view class="nomore" v-if="flag">~~没有更多了~~</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				goods:[],
				pageindex:1,
				flag:false
			}
		},
		onLoad() {
			this.getGoods()
		},
		onReachBottom() {
			// 判断是否还有更多数据
			if(this.goods.length < this.pageindex*10){
				return this.flag = true
			}
			this.pageindex++
			this.getGoods()
		},
		methods: {
			async getGoods(){
				const res = await this.$http({
					url:'/api/getgoods',
					data:{
						pageindex:this.pageindex
					}
				})
				this.goods = this.goods.concat(res)
			}
		}
	}
</script>

<style lang="scss" scoped>
.goods{
	background: #eee;
	
	.nomore{
		width: 100%;
		height: 100rpx;
		line-height: 100rpx;
		text-align: center;
		color: #999;
		font-size: 20rpx;
	}
}
</style>
